/* 
 * File:   QImageSaver.cpp
 * Author: matt
 * 
 * Created on 18 May 2010, 20:06
 */

#include "QImageSaver.h"

QImageSaver::QImageSaver() {
    layout = new QGridLayout(this);
    frame_count = 0;
    save_enable = false;
    save_checkbox = new QCheckBox("Save output");
    save_checkbox->setChecked(false);
    layout->addWidget(save_checkbox);
    connect(save_checkbox, SIGNAL(stateChanged(int)), this, SLOT(saveImageEnable(int)));

}

QImageSaver::~QImageSaver() {
}

void QImageSaver::setImage(QImage image) {
    if (save_enable == true) {

        std::ostringstream ss;
        ss << std::setw(7) << std::setfill('0') << frame_count;
        QString filename = ss.str().c_str();
        filename.append(".jpeg");

        cerr << "Saving file: " << filename.toStdString().c_str() << endl;
        image.save(filename, "jpg");
        frame_count++;
    }
}

void QImageSaver::saveImageEnable(int passed) {
    if (passed == 0)save_enable = false;
    if (passed == 2)save_enable = true;
}